package cn.alm.allinoneboot.interceptor;

import cn.alm.allinoneboot.common.CommonResult;
import cn.alm.allinoneboot.dto.CommonDto;
import cn.alm.allinoneboot.utils.Md5Util;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("md5")
public class Md5Controller {

    @PostMapping("encrypt")
    public CommonResult encrypt(@RequestBody CommonDto dto) throws Exception {
        String password = dto.getPassword();
        String encrypt = Md5Util.encrypt(password);
        CommonResult cr = new CommonResult();
        cr.ok();
        cr.setData(encrypt);
        return cr;
    }

    @PostMapping("decrypt")
    public CommonResult decrypt(@RequestBody CommonDto dto) throws Exception {
        String password = dto.getPassword();
        String encrypted = dto.getEncrypted();
        boolean decrypt = Md5Util.decrypt(password, encrypted);
        CommonResult cr = new CommonResult();
        cr.ok();
        cr.setData(decrypt);
        return cr;
    }
}
